package com.base.cn.platform.os.controller.user.account.cash;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.common.utils.DateUtils;
import com.base.cn.platform.os.service.manage.user.account.CusUserCashRecordService;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * 用户账户提现记录Controller
 *
 * @author s.li
 * @date 2018/12/03
 */
@Controller
@RequestMapping("/admin/user/account/cash")
public class AdminCusUserCashRecordController extends AdminBaseController {

    @Autowired
    private CusUserCashRecordService cusUserCashRecordService;


    /**
     * 审核提现
     * @param request
     * @param id
     * @param status
     * @param rejectText
     * @return
     */
    @RequestMapping("/auditPass")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.USER, action = "学员用户审核提现")
    public Map<String,Object> auditPass(HttpServletRequest request,
                                        @RequestParam("id") BigDecimal id,
                                        @RequestParam("status") int status,
                                        @RequestParam(value = "rejectText",required = false) String rejectText){
        BigDecimal sysUserId = loginUtil.getLoginUserId(request);
        JsonObject sysUser = loginUtil.getLoginUser(request);
        String userName = sysUser.get("username").getAsString();
        Map<String,Object> resultMap = cusUserCashRecordService.auditPass(id,sysUserId,status,rejectText);
        resultMap.put("userName",userName);
        resultMap.put("examineTime", DateUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        return resultMap;
    }

    /**
     * 查询用户提现记录
     * @return 列表页面
     */
    @RequestMapping("/queryUserCashRecordList")
    public String queryUserCashRecordList(){
        return resultPage("/user/account/cash/user-cash-record-list");
    }

    /**
     * 加载数据列表
     * @param model
     * @param params 查询条件
     * @param currentPage 页码
     * @return
     */
    @RequestMapping("/ajaQueryUserCashRecordList")
    public String ajaQueryUserCashRecordList(Model model, @RequestBody Map<String,Object> params,
                                             @RequestParam("currentPage") int currentPage){
        params.put("userData",true);
        params.put("examineUserData",true);
        Map<String,Object> dataMap = cusUserCashRecordService.findUserCashRecordListPage(params,currentPage,10);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/user/account/cash/user-cash-record-ajax-list");
    }
}
